module myfiles
  character(len=256) :: ICDir,ICBase,OutDir,Snapshot
  character(len=256) :: Paramfile
end module myfiles

module numbers
  ! set precision of single and double precision real and integers
  integer, parameter :: singleR = selected_real_kind(p=6,r=37)
  integer, parameter :: doubleR = selected_real_kind(p=15,r=307)
  integer, parameter :: singleI = selected_int_kind(9)
  integer, parameter :: doubleI = selected_int_kind(18)
end module numbers

module globals
  integer   :: logunit
  character(len=256) :: logfile
  integer*4 :: NumSnaps_Total,NumSnaps_Local,NumSnaps_Master,ntotal
  integer*4 :: iStart,iEnd
  integer*4 :: iSnapFirst,iSnapFinal
  integer*4, allocatable :: MaskParticleIDs(:)
  integer*4, allocatable :: MasterTag(:),MasterTagReduced(:)
  integer*4, allocatable :: MasterIDs(:),MasterTagIndex(:)
  real*4, dimension(3) :: HaloCentre
  logical :: ihdf5,ibinary,iARJ
end module globals

module grid
  integer*4 :: nstep
  integer*4 :: IntDone ! Number of particles for whom interactors have been found
  integer*4 :: iPer ! Periodic wraparound?
  integer*4, dimension(3) :: nmesh
  integer*4, allocatable :: lmesh(:)
  integer*4, parameter :: NumMaxCells = 2048
  integer, allocatable :: imesh(:,:,:)
  real*4 :: IntLength,stepsize
  real*4, dimension(3) :: Lbox,dx
  real*4, dimension(3,2) :: xlim
  logical, allocatable :: imesh_tag(:,:,:)
end module grid

module arj_mesh
  integer*4 :: imin,imin_init,ifac
  integer*4, parameter :: nmesh = 64
  integer*4, dimension(1) :: Lindex
  integer*4, dimension(nmesh,nmesh,nmesh) :: arjmesh = 0
  real*4 :: Ltest,dx
  real*4, parameter :: downfac = (39.0e0 / 41.0e0)
  real*4, dimension(3) :: xc,Lbox
  real*4, dimension(3,2) :: xlim
end module arj_mesh


module particles
  implicit none
  
  type headerstruct
     integer*4, dimension(6):: NumPart_ThisFile
     integer*4, dimension(6) :: NumPart_Total
     integer*4, dimension(6) :: NumPart_Total_HighWord
     real*8, dimension(6) :: MassTable
     real*8 :: ExpansionFactor
     real*8 :: Time_GYR
     real*8 :: Redshift
     real*8 :: BoxSize
     integer*4 :: NumFilesPerSnapshot
     real*8 :: Omega0
     real*8 :: OmegaBaryon
     real*8 :: OmegaLambda
     real*8 :: HubbleParam
     integer*4 :: Flag_Sfr
     integer*4 :: Flag_Cooling
     integer*4 :: Flag_StellarAge
     integer*4 :: Flag_Metals
     integer*4 :: Flag_Feedback
     integer*4 :: Flag_Entropy_Instead_U
     real*4    :: IC_x0
     real*4    :: IC_y0
     real*4    :: IC_z0
     real*4    :: IC_r0
  end type headerstruct
  
  type particlestruct
     real*4,    allocatable :: Coordinates(:,:)
     real*4,    allocatable :: Density(:)
     real*4,    allocatable :: Mass(:)
     real*4,    allocatable :: Metallicity(:)
     integer*4, allocatable :: ParticleIDs(:)
     real*4,    allocatable :: SmoothedMetallicity(:)
     real*4,    allocatable :: SmoothingLength(:)
     real*4,    allocatable :: StarFormationRate(:)
     real*4,    allocatable :: StellarFormationTime(:)
     real*4,    allocatable :: Temperature(:)
     real*4,    allocatable :: Velocity(:,:)
     real*4,    allocatable :: WindFlag(:,:)
  end type particlestruct
  
  type(headerstruct) :: header
  type(particlestruct) :: In0, In1, In2, In3, In4, In5
  integer*4 :: NumIn0,NumIn1,NumIn2,NumIn3,NumIn4,NumIn5
  

end module particles
